<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<!--  -->

<body>
    <div id="app">
        <div id="home">
            <span>首页</span>

            <button-counter></button-counter>

            <lk-box></lk-box>
        </div>

        <div id="message">
            <span>消息</span>

            <button-counter></button-counter>
        </div>

        <div id="mine">
            <span>我的</span>
        </div>

        <!-- 根目录 -->
        <button-counter></button-counter>
    </div>
    <script src="js/vue.js"></script>

    <script>
        // 1. 创建 vue 实例
        const app = Vue.createApp({
            data() {
                return {
                }
            }
        });

        // 2. 定义一个组件（全局组件）, 这里的 命名 'button-counter' 与  'ButtonCounter' 是等效的
        app.component('button-counter', {
            data() {
                return {
                    count: 0,
                }
            },
            template: `
                <button @click="count++"> 你点击了按钮 {{count}} 次 </button>
            `,
        });

        app.component('lk-box', {
            data() {
                return {
                    count: 0,
                }
            },
            // 在组件内部嵌套组件
            template: `
                <div style="width:200px; height: 200px; background-color: red;">
                    盒子组件
                    <button-counter></button-counter>
                </div>
            `,
        });

        // 3. 挂载
        app.mount("#app");

    </script>
</body>

</html>